package com.tech

import com.tech.common.KuduUtil.getIdsByGroupId
import com.tech.common.{KafkaUtil, KuduUtil}
import com.tech.config.ApplicationConfig

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer


//156430d5-67af-4475-b7a6-1f5140f8d301

/**
 * 初始化群组活动
 */
object InitializeGroupActivity4D365 {

  def start(activityId: String): Unit = {

    //租户id
    val project = ApplicationConfig.PROJECT
    //获取下级节点map（节点id -> 下级节点NextNode）
    val nextNodeMap = KuduUtil.getNextNodes4D365(ArrayBuffer(activityId))
    //获取客群map（客群id -> set(客户id)）
    val groupMap = KuduUtil.getGroups4D365(ArrayBuffer(activityId))
    //获取所有静态客户节点
    val groupNodeMap = KuduUtil.getGroupNodes4D365(activityId)
    //获取A/B Test节点map
    val testNodeMap = KuduUtil.getTestNodes4D365(ArrayBuffer(activityId))
    //获取行为节点map
    val behaviorNodeMap = KuduUtil.getBehaviorNodes4D365(ArrayBuffer(activityId))
    //获取等待节点map
    val waitNodeMap = KuduUtil.getWaitNodes4D365(ArrayBuffer(activityId))


    //初始化客群表数据
    KuduUtil.insertGroups4Map(groupMap, project, activityId)
    //依次处理所有客户节点
    groupNodeMap.foreach(
      groupNode => {

        println("groupId:" + groupNode._2)
        //保存客户参与活动记录
        KuduUtil.insertCustomerActivity4Group(groupNode._2, activityId)
        KafkaUtil.send2Kafka4Group(ApplicationConfig.CUSTOMER_NODE_TOPIC, project, activityId, groupNode._1, groupNode._2)
        InitializeGroupActivity.passNode(project, groupNode._2, activityId, groupNode._1, behaviorNodeMap, nextNodeMap, testNodeMap, waitNodeMap, groupMap)

      }
    )

    println("执行完毕")


  }

  def main(args: Array[String]): Unit = {

    val map = new mutable.HashMap[String, mutable.Set[String]]
    // 设置查询条件
    val set: mutable.Set[String] = getIdsByGroupId("5d945397-8340-ec11-8c62-00224859f3ae")

    println(set.size)

    map.put("001", set)


    println(System.currentTimeMillis())
    KuduUtil.insertGroups4Map(map, ApplicationConfig.PROJECT, "001")
    println(System.currentTimeMillis())
  }


}
